package edu.gdkm.dao;

import edu.gdkm.pojo.User;
import org.apache.ibatis.annotations.*;
import java.util.List;

public interface UserDAO {
    
    // 根据ID查询用户
    @Select("SELECT * FROM user WHERE id = #{id}")
    User findById(Long id);
    
    // 根据用户名查询用户
    @Select("SELECT * FROM user WHERE username = #{username}")
    User findByUsername(String username);
    
    // 查询所有用户
    @Select("SELECT * FROM user")
    List<User> findAll();
    
    // 根据用户类型查询用户列表
    @Select("SELECT * FROM user WHERE user_type = #{userType}")
    List<User> findByUserType(Integer userType);
    
    // 插入新用户
    @Insert("INSERT INTO user(username, password, email, phone, user_type, avatar, status, create_time, update_time) " +
            "VALUES(#{username}, #{password}, #{email}, #{phone}, #{userType}, #{avatar}, #{status}, #{createTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(User user);
    
    // 更新用户信息
    @Update("UPDATE user SET username=#{username}, password=#{password}, email=#{email}, phone=#{phone}, " +
            "user_type=#{userType}, avatar=#{avatar}, status=#{status}, update_time=#{updateTime} WHERE id=#{id}")
    int update(User user);
    
    // 根据ID删除用户
    @Delete("DELETE FROM user WHERE id = #{id}")
    int deleteById(Long id);
    
    // 根据用户名删除用户
    @Delete("DELETE FROM user WHERE username = #{username}")
    int deleteByUsername(String username);
}
